package cn.tedu.boot31.controller;

import cn.tedu.boot31.entity.User;
import cn.tedu.boot31.mapper.UserMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired(required = false)
    private UserMapper mapper;

    @RequestMapping("/regA")
    public int regA(@RequestBody User user){

        User u = mapper.select(user.getUsername());
        if(u!=null){
            return 2;
        }
        mapper.insert(user);
        return 1;
    }

    @RequestMapping("/loginA")
    public int loginA(@RequestBody User user){
        User u = mapper.select(user.getUsername());
        if (u==null){
            return 2;
        }
        if (!u.getPassword().equals(user.getPassword())){
            return 3;
        }
        return 1;
    }
}
